﻿#region 命名空间

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Text.RegularExpressions;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using WinnerCMS.BLL;
using WinnerCMS.Common;
using WinnerCMS.Model;
using WinnerCMS.Model.Attribute;
using WinnerCMS.Model.Enum;

#endregion

namespace WinnerCMS.WebUI.Admin.DataBase
{
    [Access("271005")]
    public partial class Replace : WebFactory.PageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                new ModelManage().BindDDL(this.ddlModel, "");

                this.ddlModel.SelectedIndex = 0;


                new CategoryManage().BindDDL(this.ddlCategory, BindOption.NoLink, "所有栏目",
                    byte.Parse(this.ddlModel.SelectedValue));

                new ModelManage().GetFields(this.lblField, byte.Parse(this.ddlModel.SelectedValue));
            }
        }

        protected void ddlModel_SelectedIndexChanged(object sender, EventArgs e)
        {
            new CategoryManage().BindDDL(this.ddlCategory, BindOption.NoLink, "所有栏目",
                byte.Parse(this.ddlModel.SelectedValue));

            new ModelManage().GetFields(this.lblField, byte.Parse(this.ddlModel.SelectedValue));
        }

        protected void btnOK_Click(object sender, EventArgs e)
        {
            if (this.lblField.SelectedIndex == -1)
            {
                MsgBox.Message("请选择字段", this.UpdatePanel1);
                return;
            }
            if (this.txtOldString.Text.Length == 0)
            {
                MsgBox.Message("请输入“原字符”。", this.UpdatePanel1);
                return;
            }
            var Fields = new MyStringBuilder();
            foreach (ListItem li in this.lblField.Items)
            {
                if (li.Selected)
                {
                    Fields.Append(li.Text + ",");
                }
            }
            Fields.TrimEnd();

            new FieldManage().RepalceString(byte.Parse(this.ddlModel.SelectedValue), this.ddlCategory.SelectedValue,
                Fields.ToString(), this.txtOldString.Text.Trim(), this.txtNewString.Text.Trim(),
                this.RBL_ReplaceType.SelectedIndex);

            MsgBox.Message("执行完毕。", this.UpdatePanel1);
        }
    }
}